﻿@model SCMS.UI.Models.GetSelectedItems
@{AjaxOptions ajaxOpts = new AjaxOptions
  {
      UpdateTargetId = "TADetailsDiv",
      LoadingElementId = "loading",
      HttpMethod = "Post",
      Url = Url.Action("AddSupplier/" + ViewBag.TAID),
      OnBegin = "return validateSupplier();",
      OnSuccess = "CloseDialog"
  };}

<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>

<table align="center" style="margin-left: auto; margin-right: auto;"><tr><td align="center">
    <div style="width:auto; padding:6px; border:1px solid #A7B601; background:#fff; border-radius: 6px 6px 6px 6px; margin-left: auto; margin-right: auto;">
    @using (Ajax.BeginForm(null, null, ajaxOpts, new { @class = "form" }))
    {
        @Html.ValidationSummary(true)
            <h4>Choose Supplier</h4>
            <table border="0" cellpadding="0" cellspacing="0" width="400">
                <tr>
                    <td width="40%" align="right">
                        Supplier Name:
                    </td>
                    <td width="60%">
                        @Html.DropDownListFor(model => model.SupplierID, Model.Suppliers, "--Select Supplier--", new { @id = "cbSupplier" })<br />
                        @Html.ValidationMessageFor(model => model.SupplierID, "Supplier is required")
                        @Html.HiddenFor(model => model.EntityTenderBidder.Id)                        
                    </td>
                    <td title="Add New Supplier">
                        <a href="#" onclick="sendRequest('/TenderAnalysis/AddNewSupplier4TA/@ViewBag.TAID', 'popup-page', 'popup-loading');CenterPopup();"><img src="../../Content/images/Add-Green-Button-icon.png" alt="Add New Supplier" /></a>
                    </td>
                </tr>
            </table>
            <hr />
            <h4>
                Order Request Items
            </h4>
            <table width="400" align="center" cellspacing="0" cellpadding="0" border="1" style="border: 1px solid grey;
                border-collapse: collapse;">
                <tr class="gridheader">
                    <th width="40%">
                        Item Name
                    </th>
                    <th width="60%">
                        Unit Cost
                    </th>
                </tr>
                @{ string textboxId = "";}
                @for (int i = 0; i < Model.Itemselected.Count; i++)
                {
                    textboxId = "tb" + i;
                    <tr>
                        <td align="left">
                            @Html.DisplayFor(s => s.Itemselected[i].ItemName)
                        </td>
                        <td align="left">
                            @Html.TextBoxFor(s => s.Itemselected[i].UnitCost, new { @class = "numericTb", @id = textboxId, @autocomplete = "off" })<br />
                            @Html.ValidationMessageFor(s => s.Itemselected[i].UnitCost, "Required")
                        </td>
                    </tr>
                    @Html.HiddenFor(s => s.Itemselected[i].EntityTBQuote.OrderRequestItemId)
                }
            </table>
            <hr />
            <h4>
                Terms and Conditions</h4>
            <table width="400">
                @for (int j = 0; j < Model.OtherNoneListItems.Count; j++)
                {
                    <tr>
                        <td align="right" style="width: 40%;">
                            @Html.DisplayFor(s => s.OtherNoneListItems[j].ItemName):
                        </td>
                        <td align="left" width="60%">
                            @if (Model.OtherNoneListItems[j].ItemName == "Transport Cost")
                            { 
                                @Html.TextBoxFor(s => s.OtherNoneListItems[j].UnitCost, new { @class = "numericTb", @id = "transportTb", @autocomplete = "off" })<br />
                                @Html.ValidationMessageFor(s => s.OtherNoneListItems[j].UnitCost, "Transport Cost is required")
                            }
                            else if (Model.OtherNoneListItems[j].ItemName == "Delivery Date")
                            {
                                @Html.EditorFor(s => s.OtherNoneListItems[j].DeliveryDate)
                                @Html.ValidationMessageFor(s => s.OtherNoneListItems[j].DeliveryDate)
                            }
                            else
                            { 
                                @Html.TextBoxFor(s => s.OtherNoneListItems[j].ItemValue, new { @autocomplete = "off" })<br />
                                @Html.ValidationMessageFor(s => s.OtherNoneListItems[j].ItemValue)
                            } 
                        </td>
                    </tr>
                    @Html.HiddenFor(s => s.OtherNoneListItems[j].ItemName)
                }
                @for (int k = 0; k < Model.OtherListItemsz.Count; k++)
                {
                    <tr>
                        <td align="right">
                            @Html.DisplayFor(s => s.OtherListItemsz[k].ItemName):
                            @Html.HiddenFor(s => s.OtherListItemsz[k].ItemName)
                        </td>
                        <td align="left">
                            @Html.DropDownListFor(x => x.OtherListItemsz[k].ItemID, Model.OtherListItemsz[k].ItemsList)<br />
                            @Html.ValidationMessageFor(s => s.OtherListItemsz[k].ItemID)
                        </td>
                    </tr>
                }
                <tr>
                    <td>
                    </td>
                    <td>
                        <input type="submit" class="btn green"  value="Add Supplier To Analysis" />
                    </td>
                </tr>
            </table>
            <div style="text-align: center;">
                @if (Model.IsSupplierSaved)
                {
                    <span class="action_message">@Model.UserMessage</span>
                }
                else
                {<span class="field-validation-error">@Model.UserMessage</span> }
            </div>
    }
    </div>
    </td></tr></table>